% tests morphological operations
% input:  count ... approxmiate number of tests performed
% output: se    ... last used structure element
%         img   ... last used image
function [se img] = testmorph(count)
  m = 1;
  for i = 1:count
    w = int16(rand()*40);
    h = int16(rand()*40);

    ws = int16(rand()*5)*2 + 1;
    hs = int16(rand()*5)*2 + 1;

    if (w < ws) || (h < hs)
      continue;
    end

    img = uint8(rand(h, w)*255);
    se  = logical(rand(hs,ws) < 0.5);

    miimg = midilate(img, se);
    imimg = imdilate(img, strel(se));

    miimge = mierode(img, se);
    imimge = imerode(img, strel(se));

    m = max(max(imabsdiff(uint8(miimg), uint8(imimg))));
    m = m + max(max(imabsdiff(uint8(miimge), uint8(imimge))));
    if m
      break;
    end
  end

  if m
    disp('Error!!!');
  else
%    se = 0;
%    img = 0;
    disp('No Error!');
  end

